package com.qk.mangement.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.customer.AddCustomerDTO;
import com.qk.dto.customer.QueryPageCustomerDTO;
import com.qk.dto.customer.UpdateCustomerDTO;
import com.qk.entity.Customer;
import com.qk.mangement.service.CustomerService;
import com.qk.vo.customer.CustomerVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *Date:2025/10/21
 *Author:zxc
 *Description
*/

@RestController
@RequestMapping("/customers")
@Slf4j
public class CustomerController {
    @Autowired
    private CustomerService customerService;


    @GetMapping
    public Result queryListByPage(QueryPageCustomerDTO queryPageCustomerDTO){
        log.info("客户分页查询参数：{}", queryPageCustomerDTO);
        PageResult<CustomerVO> queryListByPageVO = customerService.queryListByPage(queryPageCustomerDTO);
        return Result.success(queryListByPageVO);
    }


    @PostMapping
    public Result addCustomer(@RequestBody AddCustomerDTO addCustomerDTO){
        log.info("添加客户参数：{}", addCustomerDTO);
        customerService.addCustomer(addCustomerDTO);
        return Result.success();
    }


    @GetMapping("/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("查询客户参数：{}", id);
        Customer customer = customerService.queryById(id);
        return Result.success(customer);
    }


    @PutMapping
    public Result updateCustomer(@RequestBody UpdateCustomerDTO updateCustomerDTO){
        log.info("修改客户参数：{}", updateCustomerDTO);
        customerService.updateCustomer(updateCustomerDTO);
        return Result.success();
    }
}

